package com.pitaya.framework.common;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.mail.Email;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;

public class MailUtils {
	private static final Log log = LogFactory.getLog(MailUtils.class);
	public static final String AUTH_USER = "winwine";
	public static final String AUTH_PASS = "winwine0755";
	public static final String CHARSET = "UTF-8";
	public static final String HOST_NAME = "smtp.yeah.net";
	public static final String FORM = "winwine@yeah.net";

	public static boolean sendHtmlEmail(String subject, String msg, String... to) {
		Email email = new HtmlEmail();
		email.setAuthentication(AUTH_USER, AUTH_PASS);
		email.setCharset(CHARSET);
		email.setSubject(subject);
		try {
			email.setHostName(HOST_NAME);
			email.setFrom(FORM);
			email.setMsg(msg);
			email.addTo(to);
			email.send();
			return true;
		} catch (EmailException e) {
			log.error(e.getMessage());
		}
		return false;
	}

	public static void main(String[] args) throws EmailException {
		sendHtmlEmail("异常报告！", "<b>异常报告!</b>", new String[] { "23381328@qq.com" });
	}
}
